import 'package:chaos_flutter3/app/notifications/TabChangeMyNotification.dart';
import 'package:chaos_flutter3/app/pages/home/tabs/infos/index.dart';
import 'package:chaos_flutter3/app/pages/home/tabs/mine/index.dart';
import 'package:chaos_flutter3/app/widgets/BaseBottomNavigationBar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';

class HomePage extends HookWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<Widget> tabs = [const InfoTab(), const MineTab()];

    final tabIndex = useState(0);

    buildBottomNavigationBar() => NotificationListener<TabChangeMyNotification>(
          onNotification: (notification) {
            tabIndex.value = notification.tabIndex;
            return true;
          },
          child: const BaseBottomNavigationBar(),
        );

    return Scaffold(
        appBar: AppBar(
          leading: const IconButton(
            icon: Icon(Icons.menu),
            tooltip: 'Navigation menu',
            onPressed: null,
          ),
          title: const Text('Example title'),
          actions: const [
            IconButton(
              icon: Icon(Icons.search),
              tooltip: 'Search',
              onPressed: null,
            ),
          ],
        ),
        body: Container(
          constraints: const BoxConstraints.expand(),
          decoration: const BoxDecoration(
              gradient: LinearGradient(
                  colors: [Color(0xffFFFFFF), Color(0xffE8E7F6)],
                  begin: Alignment.topCenter,
                  end: Alignment.bottomCenter)),
          child: tabs[tabIndex.value],
        ),
        bottomNavigationBar: buildBottomNavigationBar());
  }
}
